package persistent.imple;

import java.util.List;

import basic.HibBaseDAO;
import model.TAdmin;
import model.TScore;
import persistent.dao.ScoreDAO;

public class ScoreDAOImpl implements ScoreDAO {
	private HibBaseDAO dao = null;
			public ScoreDAOImpl() {
		super();
		dao = new HibBaseDAO();
		}
	@Override
	public TScore selectScore(String stuid) {
		String hql="from TScore where stuid=?";
		Object []param={stuid};
		List list = dao.select(hql, param);
		if(list!=null && list.size()>0)
		return (TScore)list.get(0);
		else
		return null;
	}

	@Override
	public boolean addScore(TScore score) {
		// TODO Auto-generated method stub
		TScore table=new TScore();
		table.setCoursename(score.getCoursename());
		table.setStuid(score.getStuid());
		table.setGrade(score.getGrade());
		if (dao.insert(table)>0)
			return true;
		else
			return false;
	}
	@Override
	public boolean updateScore(TScore score) {
		// TODO Auto-generated method stub
		TScore table=(TScore)dao.findById(TScore.class, score.getStuid());
		table.setCoursename(score.getCoursename());
		table.setStuid(score.getStuid());
		table.setGrade(score.getGrade());
		return dao.update(table);
	}
	@Override
	public List<TScore> getListByID(String stuid) {
		// TODO Auto-generated method stub
		String hql = "from TScore where stuid = ?";
		Object para[] ={stuid};
		
		List<TScore> list =dao.select(hql, para);
		return list;
	}

}
